package com.weds.data_sync.controller;

import com.weds.data_sync.pojo.dto.PageDto;
import com.weds.data_sync.pojo.dto.ScriptGroupDto;
import com.weds.data_sync.pojo.entity.DataSyncScriptGroupDO;
import com.weds.data_sync.service.ScriptGroupService;
import com.weds.data_sync.util.JsonData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 脚本分组表 前端控制器
 * </p>
 *
 * @author lhw
 * @since 2023-12-29
 */
@Tag(name = "脚本分组")
@RestController
@RequestMapping("/api/group/v1")
public class ScriptGroupController {

    @Autowired
    private ScriptGroupService scriptGroupService;

    @Operation(summary = "增加分组")
    @PostMapping("/add")
    public Integer add(@Validated @RequestBody ScriptGroupDto scriptGroupDto) {
        return scriptGroupService.add(scriptGroupDto);
    }

    @Operation(summary = "删除分组")
    @PostMapping("/del")
    public Integer del(@RequestBody ScriptGroupDto scriptGroupDto) {
        return scriptGroupService.del(scriptGroupDto.getIds());
    }

    @Operation(summary = "修改分组")
    @PostMapping("/update")
    public Integer update(@Validated @RequestBody ScriptGroupDto scriptGroupDto) {
        return scriptGroupService.update(scriptGroupDto);
    }

    @Operation(summary = "查询分组")
    @PostMapping("/query")
    public JsonData.PageData<DataSyncScriptGroupDO> queryData(@Validated @RequestBody PageDto pageDto) {
        return scriptGroupService.queryData(pageDto);
    }
}
